package com.e.dianshang.service.impl;

import com.e.dianshang.controller.util.Constant;
import com.e.dianshang.controller.util.GetOpenIDUtil;
import com.e.dianshang.mapper.UserMapper;
import com.e.dianshang.pojo.Ticket;
import com.e.dianshang.pojo.User;
import com.e.dianshang.service.UserService;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    @Override
    public Map<String, Object> isRegistry(String code) {
        Map map = GetOpenIDUtil.oauth2GetOpenid(Constant.APPID, code, Constant.SECRET);
        String openid = (String) map.get("openid");
        Map u = userMapper.findUserByOpenId(openid);
        Map<String, Object> ret = new HashedMap<>();
        if (u != null) {
            ret.put("retCode", "success");//返回判断标志位
            ret.put("userInfo", u);//返回的信息
        } else {
            ret.put("retCode", "fail");
        }
        ret.put("openid", openid);
        return ret;
    }

    @Override
    public Integer addUser(Map map) {
        return userMapper.addUser(map);
    }

    @Override
    public Integer updateUser(Map map) {
        return userMapper.updateUser(map);
    }

    @Override
    public List<Ticket> selectTicketByphone(String openid, String startTime) {
        return userMapper.selectTicketByphone(openid, startTime);
    }

    @Override
    public List<Ticket> selectTicketByphone1(String openid) {
        return userMapper.selectTicketByphone1(openid);
    }

    @Override
    public List<Ticket> selectTicketByphone2(String openid, String startTime) {
        return userMapper.selectTicketByphone2(openid, startTime);
    }

    @Override
    public List<Ticket> selectAllTicket(String openid) {
        return userMapper.selectAllTicket(openid);
    }

    @Override
    public User selectByOpenid(String openid) {
        User user=new User();
        user.setOpenid(openid);
        return userMapper.selectOne(user);
    }



}